<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*----------------------------------------------------------------------------
<span class='line'>  2</span>  | Copyright (c) 2009 Matthew B. Brophy (matt@brophy.org).  
<span class='line'>  3</span>  | Liscense: MIT License (http://www.opensource.org/licenses/mit-license.php)
<span class='line'>  4</span>  |
<span class='line'>  5</span>  | $Id: D__matt_Computer_JavaScript_orgbrophyjs_trunk_org_brophy_js_util.js.html 30 2009-07-31 03:13:23Z matt@brophy.org $
<span class='line'>  6</span>  -----------------------------------------------------------------------------*/</span><span class="WHIT">
<span class='line'>  7</span> 
<span class='line'>  8</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">org</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>  9</span> </span><span class="WHIT">    </span><span class="NAME">org</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">org</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 10</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">org.brophy</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 11</span> </span><span class="WHIT">    </span><span class="NAME">org.brophy</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">org.brophy</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">org.brophy.js</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 13</span> </span><span class="WHIT">    </span><span class="NAME">org.brophy.js</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">org.brophy.js</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 14</span> 
<span class='line'> 15</span> </span><span class="COMM">/** 
<span class='line'> 16</span>  * @namespace 
<span class='line'> 17</span>  * @description Utilities namespace in the org.brophy.js JavaScript library 
<span class='line'> 18</span>  * @requires    This library requires the &lt;a href="http://www.mochikit.com">
<span class='line'> 19</span>  *              MochiKit&lt;/a> JavaScript library 
<span class='line'> 20</span>  *              (version 1.4+).
<span class='line'> 21</span>  */</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="NAME">org.brophy.js.util</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 23</span> 
<span class='line'> 24</span> </span><span class="COMM">/**
<span class='line'> 25</span>  * Toggle the display of an HTML element on the page.  This is done by 
<span class='line'> 26</span>  * toggling the presence of a css class, which contains a 'display:none;' 
<span class='line'> 27</span>  * rule
<span class='line'> 28</span>  *
<span class='line'> 29</span>  * @param  elemOrId  
<span class='line'> 30</span>  *         Either the element to hide/show, or the ID of an element on the 
<span class='line'> 31</span>  *         page.  If this parameter is a string, the element will be 
<span class='line'> 32</span>  *         looked up with getElementById().
<span class='line'> 33</span>  * @param  [fancy = false]
<span class='line'> 34</span>  *         Optional boolean parameter on whether use MochiKit.Visual 
<span class='line'> 35</span>  *         effects to hide the element in a more vidsually epealling way
<span class='line'> 36</span>  * @param  [duration = 0.5]
<span class='line'> 37</span>  *         Optional duraiton of the effect if the 'fancy; parameter is 
<span class='line'> 38</span>  *         TRUE.  Defaults to 0.5 seconds.
<span class='line'> 39</span>  * @return TRUE if the Element is found and the display is toggled, 
<span class='line'> 40</span>  *         FALSE otherwise.
<span class='line'> 41</span>  * @type   boolean
<span class='line'> 42</span>  */</span><span class="WHIT">
<span class='line'> 43</span> </span><span class="NAME">org.brophy.js.util.toggleDisplay</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">elemOrId</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">fancy</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">duration</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 44</span> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 45</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">elemOrId</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"string"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 46</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">elemOrId</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.DOM.getElement</span><span class="PUNC">(</span><span class="NAME">elemOrId</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 47</span> 
<span class='line'> 48</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">fancy</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">fancy</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">duration</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">duration</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0.5</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 50</span> 
<span class='line'> 51</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">elemOrId</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'> 52</span> </span><span class="WHIT">      </span><span class="PUNC">(</span><span class="NAME">elemOrId.nodeType</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NAME">org.brophy.js.constant.NODE_TYPE_ELEMENT</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 53</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 54</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">fancy</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">MochiKit.DOM.hasElementClass</span><span class="PUNC">(</span><span class="NAME">elemOrId</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"obj_none"</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">          </span><span class="NAME">elemOrId.style.display</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"none"</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 58</span> </span><span class="WHIT">      </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 59</span> </span><span class="WHIT">        </span><span class="NAME">MochiKit.Visual.blindDown</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'> 60</span> </span><span class="WHIT">          </span><span class="NAME">elemOrId</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 61</span> </span><span class="WHIT">          </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="STRN">"afterFinish"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 62</span> </span><span class="WHIT">               </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">                </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">MochiKit.DOM.removeElementClass</span><span class="PUNC">(</span><span class="NAME">elemOrId</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"obj_none"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">            </span><span class="STRN">"duration"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">duration</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">          </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">      </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">      </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">          </span><span class="NAME">MochiKit.Visual.blindUp</span><span class="PUNC">(</span><span class="NAME">elemOrId</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="STRN">"duration"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">duration</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">    </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">      </span><span class="NAME">MochiKit.DOM.toggleElementClass</span><span class="PUNC">(</span><span class="STRN">"obj_none"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">elemOrId</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 80</span> 
<span class='line'> 81</span> </span><span class="COMM">/**
<span class='line'> 82</span>  * @private
<span class='line'> 83</span>  * Utility function to write debug messages to the bottom of the page.  Good
<span class='line'> 84</span>  * substitute for alert() in IE.
<span class='line'> 85</span>  *
<span class='line'> 86</span>  * @return None
<span class='line'> 87</span>  */</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="NAME">org.brophy.js.util.debug</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">msg</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">  </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.getElement</span><span class="PUNC">(</span><span class="STRN">"obj_logging_div"</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.appendChildNodes</span><span class="PUNC">(</span><span class="NAME">document.body</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">                   </span><span class="NAME">MochiKit.DOM.DIV</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="STRN">"id"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"obj_logging_div"</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 96</span> 
<span class='line'> 97</span> </span><span class="WHIT">  </span><span class="NAME">MochiKit.Logging.log</span><span class="PUNC">(</span><span class="NAME">msg</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 98</span> 
<span class='line'> 99</span> </span><span class="WHIT">  </span><span class="NAME">MochiKit.DOM.appendChildNodes</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.getElement</span><span class="PUNC">(</span><span class="STRN">"obj_logging_div"</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.P</span><span class="PUNC">(</span><span class="NAME">msg</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>102</span> 
<span class='line'>103</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>104</span> 
<span class='line'>105</span> </span><span class="COMM">/**
<span class='line'>106</span>  * Get the left edge of an element (in pixels) relative to the left edge 
<span class='line'>107</span>  * of the document.
<span class='line'>108</span>  * @param   e
<span class='line'>109</span>  *          The element in question
<span class='line'>110</span>  * @return  The number of pixels from the left edge of the document 
<span class='line'>111</span>  *          to the left edge of the element.
<span class='line'>112</span>  * @type    integer
<span class='line'>113</span>  */</span><span class="WHIT">
<span class='line'>114</span> </span><span class="NAME">org.brophy.js.util.getLeft</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>115</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="NAME">MochiKit.Style.getElementPosition</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">x</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">  </span><span class="COMM">/*
<span class='line'>118</span>   var left = 0;
<span class='line'>119</span>   while(elem !== null && elem.offsetLeft > 0) 
<span class='line'>120</span>   { 
<span class='line'>121</span>     org.brophy.js.util.debug("Adding offsetleft");
<span class='line'>122</span>     left += elem.offsetLeft;
<span class='line'>123</span>     elem = elem.offsetParent;
<span class='line'>124</span>   }
<span class='line'>125</span>   return left;
<span class='line'>126</span>   */</span><span class="WHIT">
<span class='line'>127</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>128</span> 
<span class='line'>129</span> </span><span class="COMM">/**
<span class='line'>130</span>  * Get the top edge of an element (in pixels) relative to the top edge 
<span class='line'>131</span>  * of the document.
<span class='line'>132</span>  * @param   e
<span class='line'>133</span>  *          The element in question
<span class='line'>134</span>  * @return  The number of pixels from the top edge of the document 
<span class='line'>135</span>  *          to the top edge of the element.
<span class='line'>136</span>  * @type    integer
<span class='line'>137</span>  */</span><span class="WHIT">
<span class='line'>138</span> </span><span class="NAME">org.brophy.js.util.getTop</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>139</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="NAME">MochiKit.Style.getElementPosition</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">y</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">  </span><span class="COMM">/*
<span class='line'>142</span>   var top = 0;
<span class='line'>143</span>   while(elem !== null && elem.offsetTop > 0) 
<span class='line'>144</span>   { 
<span class='line'>145</span>     top += elem.offsetTop;
<span class='line'>146</span>     elem = elem.offsetParent;
<span class='line'>147</span>   }
<span class='line'>148</span>   return top;
<span class='line'>149</span>   */</span><span class="WHIT">
<span class='line'>150</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>151</span> 
<span class='line'>152</span> </span><span class="COMM">/**
<span class='line'>153</span>  * Get the left edge of an element (in pixels) relative to the left edge 
<span class='line'>154</span>  * of the current viewport.
<span class='line'>155</span>  * @param   e
<span class='line'>156</span>  *          The element in question
<span class='line'>157</span>  * @return  The number of pixels from the left edge of the viewport 
<span class='line'>158</span>  *          to the left edge of the element.
<span class='line'>159</span>  * @type    integer
<span class='line'>160</span>  */</span><span class="WHIT">
<span class='line'>161</span> </span><span class="NAME">org.brophy.js.util.getRelativeLeft</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>162</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT">           </span><span class="NAME">MochiKit.Style.getElementPosition</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT">           </span><span class="NAME">org.brophy.js.util.getScrollX</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">  </span><span class="COMM">/*
<span class='line'>167</span>   var left = 0;
<span class='line'>168</span>   while(elem !== null && elem.offsetLeft > 0) 
<span class='line'>169</span>   { 
<span class='line'>170</span>     org.brophy.js.util.debug("Adding offsetleft");
<span class='line'>171</span>     left += elem.offsetLeft;
<span class='line'>172</span>     elem = elem.offsetParent;
<span class='line'>173</span>   }
<span class='line'>174</span>   return left;
<span class='line'>175</span>   */</span><span class="WHIT">
<span class='line'>176</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>177</span> 
<span class='line'>178</span> </span><span class="COMM">/**
<span class='line'>179</span>  * Get the top edge of an element (in pixels) relative to the top edge 
<span class='line'>180</span>  * of the current viewport.
<span class='line'>181</span>  * @param   e
<span class='line'>182</span>  *          The element in question
<span class='line'>183</span>  * @return  The number of pixels from the top edge of the viewport 
<span class='line'>184</span>  *          to the top edge of the element.
<span class='line'>185</span>  * @type    integer
<span class='line'>186</span>  */</span><span class="WHIT">
<span class='line'>187</span> </span><span class="NAME">org.brophy.js.util.getRelativeTop</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>188</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>189</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">Math.round</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'>190</span> </span><span class="WHIT">           </span><span class="NAME">MochiKit.Style.getElementPosition</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>191</span> </span><span class="WHIT">           </span><span class="NAME">org.brophy.js.util.getScrollY</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>192</span> </span><span class="WHIT">  </span><span class="COMM">/*
<span class='line'>193</span>   var top = 0;
<span class='line'>194</span>   while(elem !== null && elem.offsetTop > 0) 
<span class='line'>195</span>   { 
<span class='line'>196</span>     top += elem.offsetTop;
<span class='line'>197</span>     elem = elem.offsetParent;
<span class='line'>198</span>   }
<span class='line'>199</span>   return top;
<span class='line'>200</span>   */</span><span class="WHIT">
<span class='line'>201</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>202</span> 
<span class='line'>203</span> </span><span class="COMM">/**
<span class='line'>204</span>  * Get the number of pixels scrolled horizontally
<span class='line'>205</span>  *
<span class='line'>206</span>  * @return  The number of pixels scrolled right
<span class='line'>207</span>  * @type    integer
<span class='line'>208</span>  */</span><span class="WHIT">
<span class='line'>209</span> </span><span class="NAME">org.brophy.js.util.getScrollX</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>210</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">o</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style.getViewportPosition</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>212</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>213</span> </span><span class="WHIT">           </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">o.x</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>214</span> </span><span class="WHIT">         </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">o.x</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>215</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>216</span> 
<span class='line'>217</span> </span><span class="COMM">/**
<span class='line'>218</span>  * Get the number of pixels scrolled horizontally
<span class='line'>219</span>  *
<span class='line'>220</span>  * @return  The number of pixels scrolled right
<span class='line'>221</span>  * @type    integer
<span class='line'>222</span>  */</span><span class="WHIT">
<span class='line'>223</span> </span><span class="NAME">org.brophy.js.util.getScrollY</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>224</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>225</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">o</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style.getViewportPosition</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>226</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>227</span> </span><span class="WHIT">           </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">o.y</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT">         </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">o.y</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>229</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>230</span> 
<span class='line'>231</span> </span><span class="COMM">/**
<span class='line'>232</span>  * Get the width of the current window
<span class='line'>233</span>  *
<span class='line'>234</span>  * @return  The width of the current window in pixels
<span class='line'>235</span>  * @type    integer
<span class='line'>236</span>  */</span><span class="WHIT">
<span class='line'>237</span> </span><span class="NAME">org.brophy.js.util.getWindowWidth</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>238</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>239</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">o</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style.getViewportDimensions</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>241</span> </span><span class="WHIT">           </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">o.w</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">         </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">o.w</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>243</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>244</span> 
<span class='line'>245</span> </span><span class="COMM">/**
<span class='line'>246</span>  * Get the width of the current window
<span class='line'>247</span>  *
<span class='line'>248</span>  * @return  The width of the current window in pixels
<span class='line'>249</span>  * @type    integer
<span class='line'>250</span>  */</span><span class="WHIT">
<span class='line'>251</span> </span><span class="NAME">org.brophy.js.util.getWindowHeight</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>252</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>253</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">o</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style.getViewportDimensions</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>254</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">o</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>255</span> </span><span class="WHIT">           </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">o.h</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>256</span> </span><span class="WHIT">         </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">o.h</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>257</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>258</span> 
<span class='line'>259</span> </span><span class="COMM">/**
<span class='line'>260</span>  * Remove leading and trailing spaces from a string.
<span class='line'>261</span>  *
<span class='line'>262</span>  * @param str  The string to trim
<span class='line'>263</span>  * @return The trimmed string
<span class='line'>264</span>  * @type String
<span class='line'>265</span>  */</span><span class="WHIT">
<span class='line'>266</span> </span><span class="NAME">org.brophy.js.util.trim</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>267</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>268</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>269</span> </span><span class="WHIT">         </span><span class="STRN">""</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">str.replace</span><span class="PUNC">(</span><span class="REGX">/^\s+|\s+$/g</span><span class="PUNC">,</span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>270</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>271</span> 
<span class='line'>272</span> </span><span class="COMM">/**
<span class='line'>273</span>  * Remove leading spaces from a string.
<span class='line'>274</span>  *
<span class='line'>275</span>  * @param str  The string to trim
<span class='line'>276</span>  * @return The trimmed string
<span class='line'>277</span>  * @type String
<span class='line'>278</span>  */</span><span class="WHIT">
<span class='line'>279</span> </span><span class="NAME">org.brophy.js.util.triml</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>280</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>281</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>282</span> </span><span class="WHIT">         </span><span class="STRN">""</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">str.replace</span><span class="PUNC">(</span><span class="REGX">/^\s+/g</span><span class="PUNC">,</span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>283</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>284</span> 
<span class='line'>285</span> </span><span class="COMM">/**
<span class='line'>286</span>  * Remove trailing spaces from a string.
<span class='line'>287</span>  *
<span class='line'>288</span>  * @param str  The string to trim
<span class='line'>289</span>  * @return The trimmed string
<span class='line'>290</span>  * @type String
<span class='line'>291</span>  */</span><span class="WHIT">
<span class='line'>292</span> </span><span class="NAME">org.brophy.js.util.trimr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>293</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>294</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">str</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>295</span> </span><span class="WHIT">         </span><span class="STRN">""</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">str.replace</span><span class="PUNC">(</span><span class="REGX">/\s+$/g</span><span class="PUNC">,</span><span class="STRN">""</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>296</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>297</span> 
<span class='line'>298</span> </span><span class="COMM">/**
<span class='line'>299</span>  * Codify all elements of the given class name.  This is meant 
<span class='line'>300</span>  * to be called on page load on a DIV or P element with this 
<span class='line'>301</span>  * class name.  IT will set the background colors of different 
<span class='line'>302</span>  * lines to alternating colors and add lines numbers.
<span class='line'>303</span>  * 
<span class='line'>304</span>  * @param The classname of the elements to be codified
<span class='line'>305</span>  * @return none
<span class='line'>306</span>  */</span><span class="WHIT">
<span class='line'>307</span> </span><span class="NAME">org.brophy.js.util.codify</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">clsName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>308</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>309</span> </span><span class="WHIT">  </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">nodes</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Selector.findDocElements</span><span class="PUNC">(</span><span class="STRN">"."</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">clsName</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>310</span> </span><span class="WHIT">  </span><span class="NAME">MochiKit.Iter.forEach</span><span class="PUNC">(</span><span class="NAME">nodes</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">n.nodeType</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">org.brophy.js.constant.NODE_TYPE_ELEMENT</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT">
<span class='line'>313</span> </span><span class="WHIT">       </span><span class="NAME">n.childNodes.length</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>314</span> </span><span class="WHIT">        </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="KEYW">return</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>315</span> 
<span class='line'>316</span> </span><span class="WHIT">    </span><span class="COMM">// Get the value of the child text node</span><span class="WHIT">
<span class='line'>317</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">codeStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">n.firstChild.nodeValue</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>318</span> 
<span class='line'>319</span> </span><span class="WHIT">    </span><span class="COMM">// Force white space</span><span class="WHIT">
<span class='line'>320</span> </span><span class="WHIT">    </span><span class="NAME">codeStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">org.brophy.js.util.trimr</span><span class="PUNC">(</span><span class="NAME">codeStr</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>321</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">codeStr.substring</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"\n"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>322</span> </span><span class="WHIT">        </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">codeStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">codeStr.substring</span><span class="PUNC">(</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>323</span> 
<span class='line'>324</span> </span><span class="WHIT">    </span><span class="NAME">codeStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">codeStr.replace</span><span class="PUNC">(</span><span class="REGX">/ /g</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"\u00a0"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>325</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>326</span> </span><span class="WHIT">    </span><span class="COMM">// Remove the children, add CSS classes, add first blank line</span><span class="WHIT">
<span class='line'>327</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.replaceChildNodes</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>328</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.addElementClass</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"obj_code_container"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>329</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.addElementClass</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"obj_code"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>330</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.appendChildNodes</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>331</span> </span><span class="WHIT">                 </span><span class="NAME">MochiKit.DOM.DIV</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="STRN">"class"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"obj_code_line_odd"</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>332</span> </span><span class="WHIT">                 </span><span class="NAME">MochiKit.DOM.BR</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>333</span> 
<span class='line'>334</span> </span><span class="WHIT">    </span><span class="COMM">// Loop through lines alternating background colors and adding</span><span class="WHIT">
<span class='line'>335</span> </span><span class="WHIT">    </span><span class="COMM">// line numbers.</span><span class="WHIT">
<span class='line'>336</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">numSpaces</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>337</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">indentStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">""</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>338</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lines</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">codeStr.split</span><span class="PUNC">(</span><span class="STRN">"\n"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">  </span><span class="WHIT">
<span class='line'>339</span> </span><span class="WHIT">    </span><span class="KEYW">for</span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">lines.length</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="NAME">i</span><span class="PUNC">++</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>340</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>341</span> </span><span class="WHIT">      </span><span class="COMM">// If this is the first line, let's set up our indention, </span><span class="WHIT">
<span class='line'>342</span> </span><span class="WHIT">      </span><span class="COMM">// i.e. how many spaces to ignore at the beginning of a string</span><span class="WHIT">
<span class='line'>343</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">i</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>344</span> </span><span class="WHIT">      </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>345</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">tempStr</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">org.brophy.js.util.triml</span><span class="PUNC">(</span><span class="NAME">lines</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>346</span> </span><span class="WHIT">        </span><span class="NAME">numSpaces</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lines</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">tempStr.length</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>347</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>348</span> 
<span class='line'>349</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">org.brophy.js.util.triml</span><span class="PUNC">(</span><span class="NAME">lines</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">substring</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">numSpaces</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">length</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>350</span> </span><span class="WHIT">      </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>351</span> </span><span class="WHIT">        </span><span class="NAME">lines</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">lines</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">substring</span><span class="PUNC">(</span><span class="NAME">numSpaces</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>352</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>353</span> </span><span class="WHIT">      </span><span class="WHIT">
<span class='line'>354</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">isEven</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">%</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>355</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">className</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">isEven</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="STRN">"obj_code_line_even"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">"obj_code_line_odd"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>356</span> 
<span class='line'>357</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">spc</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">org.brophy.js.constant.UNICODE_NBSP</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>358</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">lineDiv</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.DOM.DIV</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="STRN">"class"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">className</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>359</span> </span><span class="WHIT">                      </span><span class="NAME">spc</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">i</span><span class="PUNC">+</span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">":"</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">spc</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">lines</span><span class="PUNC">[</span><span class="NAME">i</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">spc</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">spc</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>360</span> </span><span class="WHIT">      </span><span class="NAME">MochiKit.DOM.appendChildNodes</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">lineDiv</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>361</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>362</span> 
<span class='line'>363</span> </span><span class="WHIT">    </span><span class="COMM">// Add trailing blank line</span><span class="WHIT">
<span class='line'>364</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">className</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">lines.length</span><span class="PUNC">%</span><span class="NUMB">2</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>365</span> </span><span class="WHIT">                    </span><span class="STRN">"obj_code_line_even"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>366</span> </span><span class="WHIT">                    </span><span class="STRN">"obj_code_line_odd"</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>367</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.DOM.appendChildNodes</span><span class="PUNC">(</span><span class="NAME">n</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>368</span> </span><span class="WHIT">                 </span><span class="NAME">MochiKit.DOM.DIV</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="STRN">"class"</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">className</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">MochiKit.DOM.BR</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>369</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>370</span> </span><span class="PUNC">}</span></pre></body></html>